{% comment %} post(post, is_index, post_extra_class) {% endcomment %}

  {% if 'quote, picture' contains post.type %}
    {% assign headlessPost = true %}
  {% endif %}

  {% assign post_class = 'post post-type-' | append: post.type | default: 'normal' %}
  {% assign post_class = post_class | append: ' ' | append: post_extra_class | default: '' %}
  {% if post.sticky > 0 %}
    {% assign post_class = post_class | append: ' ' | append: 'post-sticky' %}
  {% endif %}

  <article class="{{ post_class }}" itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="{{ post.url | absolute_url }}">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="{{ site.author }}">
      <meta itemprop="description" content="{{ site.signature }}">
      <meta itemprop="image" content="{% assign default_avatar = site.images | append: '/avatar.gif' %}{{ site.avatar | default: default_avatar ) }}">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="{{ site.title }}">
    </span>

    {% unless headlessPost %}
      <header class="post-header">

        {% comment %} % Not to show title for quote posts that do not have a title {% endcomment %}
        {% unless is_index and post.type == 'quote' and post.title == nil %}
          <{% if site.seo %}h2{% else %}h1{% endif %} class="post-title" itemprop="name headline">
          {% comment %} Link posts {% endcomment %}
          {% if post.link %}
              {% if post.sticky > 0 %}
                {{ post.sticky }}
                <span class="post-sticky-flag" title="{{ __.post.sticky }}">
                  <i class="fa fa-thumb-tack"></i>
                </span>
              {% endif %}
              <a class="post-title-link post-title-link-external" target="_blank" href="{{ post.link }}" itemprop="url">
                {% if post.title %}{{ post.title }}{% else %}{{  post.link }}{% endif %}
                <i class="fa fa-external-link"></i>
              </a>
            {% else %}
            {% if is_index %}
                {% if post.sticky > 0 %}
                  <span class="post-sticky-flag" title="{{ __.post.sticky }}">
                    <i class="fa fa-thumb-tack"></i>
                  </span>
                {% endif %}
                <a class="post-title-link" href="{{ post.url | relative_url }}" itemprop="url">
                {{ post.title | default: __.post.untitled }}
              </a>
            {% else %}{{ post.title }}{% endif %}
          {% endif %}
        </{% if site.seo %}h2{% else %}h1{% endif %}>
        {% endunless %}

        <div class="post-meta">
          <span class="post-time">
            {% if site.post_meta.created_at %}
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              {% if site.post_meta.item_text %}
                <span class="post-meta-item-text">{{ __.post.posted }}</span>
              {% endif %}
              <time title="{{ __.post.created }}" itemprop="dateCreated datePublished" datetime="{{ post.date | date_to_xmlschema }}">
                {{ post.date | date: site.date_format }}
              </time>
            {% endif %}

            {% if site.post_meta.created_at and site.post_meta.updated_at %}
              <span class="post-meta-divider">|</span>
            {% endif %}

            {% if site.post_meta.updated_at %}
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-check-o"></i>
              </span>
              {% if site.post_meta.item_text %}
                <span class="post-meta-item-text">{{ __.post.modified }}</span>
              {% endif %}
              <time title="{{ __.post.modified }}" itemprop="dateModified" datetime="{{ post.updated | date: site.date_format }}">
                {{ post.updated | date: site.date_format }}
              </time>
            {% endif %}
          </span>

          {% if post.categories and post.categories.size > 0 and site.post_meta.categories %}
            <span class="post-category" >
            {% if site.post_meta.created_at or site.post_meta.updated_at %}
              <span class="post-meta-divider">|</span>
            {% endif %}
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              {% if site.post_meta.item_text %}
                <span class="post-meta-item-text">{{ __.post.in }}</span>
              {% endif %}
              {% for cat in post.categories %}
                {% assign cat_url_encode = cat | url_encode | replace: '+', '%20' %}
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="{{ '/category/#/' | relative_url | append: cat_url_encode }}" itemprop="url" rel="index">
                    <span itemprop="name">{{ cat }}</span>
                  </a>
                </span>

                {% assign cat_length = post.categories.size %}
                {% if cat_length > 1 and forloop.index != cat_length %}
                  {{ __.symbol.comma }}
                {% endif %}
              {% endfor %}
            </span>
          {% endif %}

          {% if post.comments %}
            {% if site.duoshuo_shortname or site.duoshuo and site.duoshuo.shortname %}
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="{{ post.url | relative_url }}#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="{{ post.url }}" itemprop="commentCount"></span>
                </a>
              </span>
            {% elsif site.facebook_comments_plugin.enable %}
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="{{ post.url | relative_url }}#comments" itemprop="discussionUrl">
                  <span class="post-comments-count fb-comments-count" data-href="{{ post.url | absolute_url }}" itemprop="commentCount">0</span> comments
                </a>
              </span>
            {% elsif site.disqus.enable and site.disqus.count %}
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="{{ post.url | relative_url }}#comments" itemprop="discussionUrl">
                  <span class="post-comments-count disqus-comment-count"
                        data-disqus-identifier="{{ post.url }}" itemprop="commentCount"></span>
                </a>
              </span>
            {% elsif site.hypercomments_id %}
            <!--noindex-->
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="{{ post.url | relative_url }}#comments" itemprop="discussionUrl">
                  <span class="post-comments-count hc-comment-count" data-xid="{{ post.url }}" itemprop="commentsCount"></span>
                </a>
              </span>
              <!--/noindex-->
            {% elsif post.layout == 'post' and site.gentie_productKey %}
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a class="cloud-tie-join-count" href="{{ post.url | relative_url }}#comments" itemprop="discussionUrl">
                  <span class="post-comments-count join-count" itemprop="commentCount"></span>
                </a>
              </span>
            {% elsif site.changyan.enable and site.changyan.appid and site.changyan.appkey %}
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              {% if post.layout == 'post' %}
                <a href="{{ post.url | relative_url }}#SOHUCS" itemprop="discussionUrl">
                  <span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="{{ post.url }}" itemprop="commentsCount"></span>
                </a>
              {% else %}
                <a href="{{ post.url | relative_url }}#SOHUCS" itemprop="discussionUrl">
                  <span id="url::{{ post.url | absolute_url }}" class="cy_cmt_count" data-xid="{{ post.url }}" itemprop="commentsCount" ></span>
                </a>
              {% endif %}
            {% endif %}
          {% endif %}

          {% comment %} LeanCould PageView {% endcomment %}
          {% if site.leancloud_visitors.enable %}
             <span id="{{ post.url | relative_url }}" class="leancloud_visitors" data-flag-title="{{ post.title }}">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               {% if site.post_meta.item_text %}
                 <span class="post-meta-item-text">{{__.post.visitors}} </span>
               {% endif %}
                 <span class="leancloud-visitors-count"></span>
             </span>
          {% endif %}

          {% if site.busuanzi_count.enable and site.busuanzi_count.page_pv and is_index == false or is_index == nil%}
            <span class="post-meta-divider">|</span>
            <span class="page-pv">{{ site.busuanzi_count.page_pv_header }}
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>{{ site.busuanzi_count.page_pv_footer }}
            </span>
          {% endif %}

          {% if site.post_wordcount.wordcount or site.post_wordcount.min2read %}
            <div class="post-wordcount">
              {% if site.post_wordcount.wordcount %}
                {% unless site.post_wordcount.separated_meta %}
                  <span class="post-meta-divider">|</span>
                {% endunless %}
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                {% if site.post_wordcount.item_text %}
                  <span class="post-meta-item-text">{{ __.post.wordcount }}</span>
                {% endif %}
                <span title="{{ __.post.wordcount }}">
                  {{ post.content | number_of_words }}
                </span>
              {% endif %}

              {% if site.post_wordcount.wordcount and site.post_wordcount.min2read %}
                <span class="post-meta-divider">|</span>
              {% endif %}

              {% if site.post_wordcount.min2read %}
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                {% if site.post_wordcount.item_text %}
                  <span class="post-meta-item-text">{{ __.post.min2read }}</span>
                {% endif %}
                <span title="{{ __.post.min2read }}">
                  {{ post.content | number_of_words | divided_by: 200 }}
                </span>
              {% endif %}
            </div>
          {% endif %}

          {% unless site.excerpt_description and is_index %}
            {% if site.description %}
                <div class="post-description">
                    {{ post.description }}
                </div>
            {% endif %}
          {% endunless %}

        </div>
      </header>
    {% endunless %}

    <div class="post-body{% if site.han %} han-init-context{% endif %}" itemprop="articleBody">

      {% comment %} Gallery support {% endcomment %}
      {% if post.photos and post.photos.size > 0 %}
        <div class="post-gallery" itemscope itemtype="http://schema.org/ImageGallery">
          {% assign COLUMN_NUMBER = 3 %}
          {% for photo in post.photos %}
            {% assign index0_modulo_COLUMN_NUMBER = forloop.index0 | modulo: COLUMN_NUMBER %}
            {% if index0_modulo_COLUMN_NUMBER == 0 %}<div class="post-gallery-row">{% endif %}
              <a class="post-gallery-img fancybox"
                 href="{{ photo }}" rel="gallery_{{ post._id }}"
                 itemscope itemtype="http://schema.org/ImageObject" itemprop="url">
                <img src="{{ photo }}" itemprop="contentUrl"/>
              </a>
            {% if index0_modulo_COLUMN_NUMBER == 2 %}</div>{% endif %}
          {% endfor %}

          {% comment %} Append end tag for `post-gallery-row` when (photos size mod COLUMN_NUMBER) is less than COLUMN_NUMBER {% endcomment %}
          {% assign photos_size_modulo_COLUMN_NUMBER = post.photos.size | modulo: COLUMN_NUMBER %}
          {% if photos_size_modulo_COLUMN_NUMBER > 0 %}</div>{% endif %}
        </div>
      {% endif %}

      {% if is_index %}
        {% if post.description and site.excerpt_description %}
          {{ post.description }}
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="{{ post.url | relative_url }}">
              {{ __.post.read_more }} &raquo;
            </a>
          </div>
          <!--/noindex-->
        {% elsif post.excerpt  %}
          {{ post.excerpt }}
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="{{ post.url | relative_url }}{% if site.scroll_to_more %}#{{ __.post.more }}{% endif %}" rel="contents">
              {{ __.post.read_more }} &raquo;
            </a>
          </div>
          <!--/noindex-->
        {% elsif site.auto_excerpt.enable %}
          {% assign content = post.content | strip_html %}
          {{ content | slice: 0, site.auto_excerpt.length }}
          {% if content.size > site.auto_excerpt.length %}...{% endif %}
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="{{ post.url | relative_url }}{% if site.scroll_to_more %}#{{ __.post.more }}{% endif %}" rel="contents">
              {{ __.post.read_more }} &raquo;
            </a>
          </div>
          <!--/noindex-->
        {% else %}
          {% if post.type == 'picture' %}
            <a href="{{ post.url | relative_url }}">{{ post.content }}</a>
          {% else %}
            {{ post.content }}
          {% endif %}
        {% endif %}
      {% else %}
        {{ post.content }}
      {% endif  %}
    </div>

    <div>
      {% unless is_index %}
        {% include _macro/wechat-subscriber.html %}
      {% endunless %}
    </div>

    <div>
      {% unless is_index %}
        {% include _macro/reward.html %}
      {% endunless %}
    </div>

    <div>
      {% unless is_index %}
        {% include _macro/post-copyright.html %}
      {% endunless %}
    </div>

    <footer class="post-footer">
      {% if post.tags and post.tags.size != 0 and is_index == nil or is_index == false %}
        <div class="post-tags">
          {% for tag in post.tags %}
            {% assign tag_url_encode = tag | url_encode | replace: '+', '%20' %}
            <a href="{{ '/tag/#/' | relative_url | append: tag_url_encode }}" rel="tag"># {{ tag }}</a>
          {% endfor %}
        </div>
      {% endif %}

      {% unless is_index %}
      {% if site.vkontakte_api.enable and site.vkontakte_api.like %}
        {% assign vkontakte_api = true %}
      {% endif %}
      {% if site.facebook_sdk.enable and site.facebook_sdk.like_button %}
        {% assign facebook_sdk = true %}
      {% endif %}
      {% if site.rating.enable or vkontakte_api or facebook_sdk %}
        <div class="post-widgets">
        {% if site.rating.enable %}
          <div class="wp_rating">
            <div id="wpac-rating"></div>
          </div>
        {% endif %}

        {% if vkontakte_api or facebook_sdk %}
          <div class="social-like">
            {% if vkontakte_api %}
              <div class="vk_like">
                <span id="vk_like"></span>
              </div>
            {% endif %}

            {% if facebook_sdk %}
              <div class="fb_like">
                <div class="fb-like" data-layout="button_count" data-share="true"></div>
              </div>
            {% endif %}
          </div>
        {% endif %}
        </div>
      {% endif %}
      {% endunless %}

      {% unless is_index %}
      {% if post.previous or post.next %}
        <div class="post-nav" id="post-nav-id">
          <div class="post-nav-next post-nav-item">
            {% if post.next %}
              <a href="{{ post.next.url | relative_url }}" rel="next" title="{{ post.next.title }}">
                <i class="fa fa-chevron-left"></i> {{ post.next.title }}
              </a>
            {% endif %}
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            {% if post.previous %}
              <a href="{{ post.previous.url | relative_url }}" rel="prev" title="{{ post.previous.title }}">
                {{ post.previous.title }} <i class="fa fa-chevron-right"></i>
              </a>
            {% endif %}
          </div>
        </div>
      {% endif %}
      {% endunless %}

      {% if is_index %}
        {% assign per_page = paginator.per_page | default: site.posts.size %}
        {% assign index_modulo_per_page = forloop.index | modulo: per_page %}
        {% if index_modulo_per_page == 0 %}
          {% assign isLast = true %}
        {% endif %}
        {% unless isLast %}
          <div class="post-eof"></div>
        {% endunless %}
      {% endif %}
    </footer>
  </article>
